﻿using Hotel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.DAL
{
    public class MemberDAL
    {
        public MemberDAL(Mycount mycount)
        {
            Mycount = mycount;
        }

        public Mycount Mycount { get; }
        /// <summary>
        /// 会员增加
        /// </summary>
        /// <param name="member">会员实体</param>
        /// <returns>返回受影响的行数</returns>
        public int MebberAdd(Member member)
        {
            try
            {
                 Mycount.members.Add(member);
                return Mycount.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 判断是否重复
        /// </summary>
        /// <param name="Phone">手机号</param>
        /// <param name="Card">身份证</param>
        /// <returns></returns>
        public int SerchPhoneCard(string Phone,string Card)
        {
            try
            {
                int res=Mycount.members.Where(c=>c.Phopne==Phone).Count();
                if(res > 0)
                {
                    return -1;//手机号重复
                }
                int con = Mycount.members.Where(c => c.Card == Card).Count();
                if (con > 0)
                {
                    return -2;//身份证重复
                }
                return 1;
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
